import { createRouter, createWebHistory } from 'vue-router'
/* Layout */
const Layout = () => import('@/layout/LayoutIndex.vue')
/* views路由信息  */
const HomePage = () => import('@/views/dashboard/HomePage.vue')
const LoginPage = () => import('@/views/login/LoginPage.vue')
// 多层嵌套
const menu1 = () => import('@/views/nested/menu1/menu1-3.vue')
const menu1_1 = () => import('@/views/nested/menu1/menu1-1/menu1-1.vue')
const menu1_2 = () => import('@/views/nested/menu1/menu1-2/menu1-2.vue')
const menu1_2_1 = () => import('@/views/nested/menu1/menu1-2/menu1-2-1/menu1-2-1.vue')
const menu1_2_2 = () => import('@/views/nested/menu1/menu1-2/menu1-2-2/menu1-2-2.vue')
const menu1_3 = () => import('@/views/nested/menu1/menu1-3/index.vue')
const menu2 = () => import('@/views/nested/menu2/menu2.vue')
// 系统管理
const accountManage = () => import('@/views/systemManage/accountManage.vue')
const menuManage = () => import('@/views/systemManage/menuManage.vue')
const roleManage = () => import('@/views/systemManage/roleManage.vue')

/**
 * route上设置的属性说明
 * hidden: true                   默认值:false，如果设为true则不在侧边栏显示
 * alwaysShow: false              单菜单项是否显示根节点(默认不显示)，默认false: 当children长度大于1时显示，否则不显示
 * name:'router-name'             用于权限判断、设置<keep-alive>缓存状态，必须
 * meta : {
    title: 'title'                侧边栏菜单和面包屑导航的展示标题
    icon:  antd-icon              侧边栏菜单图标
    isPermission: false,          是否进行权限判定：默认值:false，false: 免权限判定
  }
 */

export const pageRoutes = [
  // 临时路由，开发时删除
  {
    path: '/nested',
    component: Layout,
    name: 'Nested',
    meta: {
      title: '模拟菜单',
      icon: 'CloudOutlined',
      isPermission: true
    },
    children: [
      {
        path: '/menu1',
        component: menu1, // Parent router-view
        name: 'Menu1',
        meta: { title: '子菜单1', isPermission: true },
        children: [
          {
            path: '/menu1-1',
            component: menu1_1,
            name: 'Menu1-1',
            meta: { title: '子菜单1-1', icon: 'FireOutlined', isPermission: true }
          },
          {
            path: '/menu1-2',
            component: menu1_2,
            name: 'Menu1-2',
            meta: { title: '子菜单1-2', isPermission: true },
            children: [
              {
                path: '/menu1-2-1',
                component: menu1_2_1,
                name: 'Menu1-2-1',
                meta: { title: '子菜单1-2-1', isPermission: true }
              },
              {
                path: '/menu1-2-2',
                component: menu1_2_2,
                name: 'Menu1-2-2',
                meta: { title: '子菜单1-2-2', isPermission: true }
              }
            ]
          },
          {
            path: '/menu1-3',
            component: menu1_3,
            name: 'Menu1-3',
            meta: { title: '子菜单1-3', isPermission: true }
          }
        ]
      },
      {
        path: '/menu2',
        component: menu2,
        name: 'Menu2',
        meta: { title: '子菜单2', isPermission: true }
      }
    ]
  },
  {
    path: '/authManage',
    name: 'authManage',
    meta: {
      title: '权限管理',
      isPermission: true
    },
    component: Layout,
    children: [
      {
        path: '/accountManage',
        name: 'accountManage',
        meta: {
          title: '用户管理',
          isPermission: true
        },
        component: accountManage
      },
      {
        path: '/menuManage',
        name: 'menuManage',
        meta: {
          title: '菜单管理',
          isPermission: true
        },
        component: menuManage
      },
      {
        path: '/roleManage',
        name: 'roleManage',
        meta: {
          title: '角色管理',
          isPermission: true
        },
        component: roleManage
      }
    ]
  }
]
const staticRoutes = [
  /**
   * 默认路由信息
   */
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: '/dashboard',
        name: 'Dashboard',
        component: HomePage,
        meta: {
          title: 'Dashboard',
          icon: 'DashboardOutlined'
        }
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: LoginPage,
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404.vue'),
    hidden: true
  }

  // 404 page must be placed at the end !!!
  /*{
    path: "/:pathMatch(.*)",
    //访问主页的时候 重定向到index页面
    redirect: "/404",
    hidden: true,
  },*/
]
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: staticRoutes
})
export function resetRouter() {
  const newRouter = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: staticRoutes
  })
  router.matcher = newRouter.matcher // reset router
}
export default router
